package cn.cdm.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/redisLock")
public class DistributedLockDemo {

    @Autowired
    StringRedisTemplate stringRedisTemplate;


    @RequestMapping("/stock")
    public String redisLock(){


        int stock = Integer.parseInt(stringRedisTemplate.opsForValue().get("stock"));
        stringRedisTemplate.opsForValue().set("stock", stock - 1 + "");
        System.out.println("StringRedisTemplate: " + (stock - 1));


        return "success";

    }

}
